<!DOCTYPE html>
<html lang="zh_CN" xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head th:include="include :: header"></head>

<body class="gray-bg">
	<div class="wrapper wrapper-content animated fadeInRight">

		<div class="row">
			<div class="col-sm-12">

				<div class="ibox-content">
					<div id="menuTree"></div>
				</div>
				<div class="form-group hidden">
					<div class="col-sm-12 col-sm-offset-12">
						<button type="submit" class="btn btn-primary">提交</button>
					</div>
				</div>
			</div>
		</div>
	</div>
	<div th:include="include :: footer"></div>


	<script type="text/javascript">
		$(document).ready(function() {
			getTreeData()
		});
		function getTreeData() {
			$.ajax({
				type : "GET",
				url : path.format("/auth/menu/listOnlyMenuTree"),
				success : function(r) {
				    var tree= JSON.parse(r);
					loadTree(tree);
				}
			});
		}
		function loadTree(tree) {
			$('#menuTree').jstree({
				'core' : {
					'data' : tree.model
				},
				"plugins" : [ "search" ]
			});
			$('#menuTree').jstree("open_all");
		}
		$('#menuTree').on("changed.jstree", function(e, data) {
		    var parentId = data.node.id;
		    var parentName = data.node.text;
//		    var parent = data.node.text;
//		    if(parent==-1){
//		        //如果是一级菜单
//                layer.msg("当前是一级菜单,不允许调整至")
//            }
			if(parentId!=-1){

			} else {
                parentId = 0;
                parentName = "根目录";
            }
            var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
            parent.layer.close(index);

            parent.$("#parentId").val(parentId);
            parent.$("#parentName").val(parentName+"(点击选择)");
		});
		
	</script>
</body>

</html>
